package com.lc.tgxm.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lc.tgxm.R;
import com.lc.tgxm.activity.MyListActivity;
import com.lc.tgxm.dialog.ClearDialog;
import com.lc.tgxm.util.Utils;
import com.zcx.helper.util.UtilToast;

import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

/**
 * TestFragment For TEST allchange
 * Created by Lei on 2017/01/03.
 */
public class TestFragment extends BaseFragment {
    private PopupWindow popWindow;
    private TextView tvMac;
    private Timer timer;

    @Override
    protected int layoutId() {
        return R.layout.fragment_test;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setBtnOnClick(R.id.btn_showcustomdialog, R.id.btn_showsystemdialog);

        popWindow = initPopWindowFromBottom(R.layout.pw_selectbz);

        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                Log.i(TAG, "onDismiss");
            }
        });

        tvMac = (TextView) rootView.findViewById(R.id.tv_mac);
//        tvMac.setText(Utils.getWifiMac(getActivity()));
//        tvMac.append("\n V1.0.1");

        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.CHINA);
                        String ymd = sdf.format(System.currentTimeMillis());
                        long dayoff = Utils.str2longTime(ymd + " 175000");
                        long cha = dayoff - System.currentTimeMillis();
                        tvMac.setText(Utils.ms2HourMinSecsColon(cha));
                    }
                });
            }
        }, 0, 1000);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_showcustomdialog:
                Utils.showDialog(getActivity(), R.string.app_name,
                        new ClearDialog.OnItemClick() {
                            @Override
                            public void onOkItemClick(View v) {
                                UtilToast.show("OK");
                            }
                        });
//                WaitDialog waitDialog = new WaitDialog(getContext());
//                waitDialog.show();
//                startVerifyActivity(MyNormalizeViewActivity.class);
                break;
            case R.id.btn_showsystemdialog:
                startVerifyActivity(MyListActivity.class);
//                startVerifyActivity(RegActivity.class);
                break;
        }
    }

    @Override
    public void onDestroy() {
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        super.onDestroy();
    }
}